package com.example.beidouapplication;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.app.Fragment;
import android.widget.Button;

import androidx.annotation.Nullable;

import com.example.beidouapplication.viewmodel.Key;
import com.example.beidouapplication.viewmodel.KeyEvent;

public class FragmentMenuIni extends Fragment implements View.OnClickListener {

    static FragmentMenuIni instance = new FragmentMenuIni();

    Button btn_row1;
    Button btn_row2;
    Button btn_row3;
    Button btn_row4;
    Button btn_row5;
    Button btn_row6;


    @Override
    public View onCreateView(
            LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState
    ) {

        View inflate = inflater.inflate(R.layout.fragment_xitong, container, false);
        return inflate;
    }


    void sendKey(int index) {
        if (Menu.stage != Menu.MENU_INI_S1) {
            Menu.keyQueue.add(new KeyEvent(Key.Esc, -1));
        }
        Menu.keyQueue.add(new KeyEvent(Key.ENTER, index));
    }

    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        btn_row1 = getActivity().findViewById(R.id.btn_xitong_row1);
        btn_row2 = (Button) getActivity().findViewById(R.id.btn_xitong_row2);
        btn_row3 = (Button) getActivity().findViewById(R.id.btn_xitong_row3);
        btn_row4 = (Button) getActivity().findViewById(R.id.btn_xitong_row4);
        btn_row5 = (Button) getActivity().findViewById(R.id.btn_xitong_row5);

        btn_row6 = (Button) getActivity().findViewById(R.id.btn_xitong_row6);


        btn_row1.setOnClickListener(this);
        btn_row2.setOnClickListener(this);
        btn_row3.setOnClickListener(this);
        btn_row4.setOnClickListener(this);
        btn_row5.setOnClickListener(this);
        btn_row6.setOnClickListener(this);




    }


    @Override
    public void onClick(View view) {
        android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();

        if (view.getId() == R.id.btn_xitong_row1) {
            sendKey(1);
//            ft.replace(R.id.contentFrame, FragmentSelfTest.instance);
        } else if (view.getId() == R.id.btn_xitong_row2) {
            sendKey(2);
//            ft.replace(R.id.contentFrame, FragmentGetBDInfo.instance);
        } else if (view.getId() == R.id.btn_xitong_row3) {
            sendKey(3);
//            ft.replace(R.id.contentFrame, FragmentSelfTest.instance);
        } else if (view.getId() == R.id.btn_xitong_row4) {
            sendKey(4);
//            ft.replace(R.id.contentFrame, FragmentSelfTest.instance);
        } else if (view.getId() == R.id.btn_xitong_row5) {
            sendKey(5);
//            ft.replace(R.id.contentFrame, FragmentSysParaInfo.instance);
        } else if (view.getId() == R.id.btn_xitong_row6) {
            sendKey(6);
//            ft.replace(R.id.contentFrame, FragmentSelfTest.instance);
        }
        ft.commit();

    }
}